<?php

class DemoController extends Controller
{
	public function actionCategories()
	{
		$data = CJSON::decode(file_get_contents("https://api.foursquare.com/v2/venues/categories?oauth_token=TUQB0BPCAR4BJVKZ0G0XJ1L10TSXONU01R4GRBDCTSN2PMVM&v=20130304"));
		$categories = $data['response']['categories'];
		foreach($categories as $key => $cat){
			$this->echoCat($cat);
		}
	}
	
	public function echoCat($cat)
	{
		$link = substr($cat['icon']['prefix'], 0, strlen($cat['icon']['prefix']) - 1).$cat['icon']['suffix'];
		echo <<<HTML
			<div>
				<div>{$cat['name']}</div>
				<div><img src="{$link}" /></div>
			</div>
HTML;
		if(isset($cat['categories'])) {
			foreach($cat['categories'] as $key => $item){
				$this->echoCat($item);
			}
		}
	}
}